<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/jsp/taglib.jsp"%>
<%@ page import="com.framework.utils.ConfigUtil" %>
<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>信息编辑窗体</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link href="${ctxStatic}/plugins/h+/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <%--<link href="${ctxStatic}/plugins/h+/css/style.min862f.css?v=4.1.0" rel="stylesheet">--%>
    <link rel="stylesheet" type="text/css" href="${ctxStatic}/plugins/h+/css/plugins/webuploader/webuploader.css">
    <link href="${ctxStatic}/plugins/h+/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">

    <link href="${ctxStatic}/plugins/h+/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/colorpicker/css/bootstrap-colorpicker.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/cropper/cropper.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/switchery/switchery.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/jasny/jasny-bootstrap.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/nouslider/jquery.nouislider.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/ionRangeSlider/ion.rangeSlider.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/ionRangeSlider/ion.rangeSlider.skinFlat.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/awesome-bootstrap-checkbox/awesome-bootstrap-checkbox.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/clockpicker/clockpicker.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/animate.min.css" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/style.min.css?v=4.0.0" rel="stylesheet"><base target="_blank">

    <style>
        .dtupload>img{
            width: 54px;
            padding-left: 39px;
            padding-top: 16px;
        }
        .dtupload>a{
            color: #268eff;
            font-size: 12px;
            position: relative;
            left: 26px;
            top: 10px;
        }.dtupload>a:hover,
         .shoplogo>a:hover{
             color:#F93;
         }.upload_pic {
              height: 70px;
              width:70px;
              position: relative;
              cursor: pointer;
              color: #ccbe9e;
              background: #fff;
              overflow: hidden;
              display: inline-block;
              *display: inline;
              *zoom: 1;
          }
        .upload_pic input {
            position: absolute;
            height:100%;
            width:100%;
            right: 0;
            top: 0;
            opacity: 0;
            filter: alpha(opacity=0);
            cursor: pointer
        }
        .upload_pic:hover {
            color: #ccbe9e;
            background: #fff;
            text-decoration: none
        }
        .posabs{
            position: absolute;
            right: 23px;
            top: 9px;
        }
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="panel-options">
        <ul class="nav nav-tabs">
            <li class="active"><a data-toggle="tab" href="tabs_panels.html#tab-0"><i class="fa fa-laptop">动态管理</i></a>
            </li>
        </ul>
    </div>

    <div class="panel-body">
        <form class="form-horizontal" onsubmit="return  false" id="form_brand">
            <div class="tab-content">
                <div id="tab-0" class="tab-pane active">
                    <div class="ibox-content">
                        <input id="row_id" value="${row.id}" name="dynamic.id" type="hidden">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">标题：</label>
                            <div class="col-sm-8">
                                <input id="title" value="${row.title}" name="dynamic.title" class="form-control" type="text">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">图片：</label>
                            <div class="col-sm-4">
                                <!--上传logo-->
                                <div class="dtupload">
                                    <a href="javascript:" class="upload_pic" style="height:80px;"><input type="file" name="fileToUpload" id="fileToUpload1" onChange="uploadFile('fileToUpload1','imgUpdate','shopPicId');">
                                        <img  id="imgUpdate" src="${pageContext.request.contextPath}/resources/image/logopic1.png" width="100%"/>
                                        <input type="hidden" id="picture" name="dynamic.picture">
                                    </a>
                                </div>
                            </div>
                        </div>
                        <%--<div class="form-group">--%>
                            <%--<label class="col-sm-3 control-label">详细说明：</label>--%>
                            <%--<div class="col-sm-9">--%>
                                <%--<textarea type="text" id="description" name="dynamic.description" class="form-control">${row.description}</textarea>--%>
                            <%--</div>--%>
                        <%--</div>--%>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">详细说明：</label>
                            <div class=" col-sm-9">
                                <!-- 加载编辑器的容器 -->
                                <script id="container" name="content" style="height:300px" type="text/plain">
                                </script>
                                <input id="graphicDetails" name="dynamic.graphicDetails" type="hidden">
                                    </div>
                                    </div>
                        <div class="form-group">
                            <div class="col-sm-offset-3 col-sm-8">
                                <button class="btn btn-primary" onclick="doSubmit();">提交</button>
                                <button id="btn_close1"  class="btn btn-primary" type="button">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

</body>
<script src="${ctxStatic}/plugins/h+/js/jquery.min.js?v=2.1.4"></script>

<!-- 配置文件 -->
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/plugins/utf8-jsp/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/plugins/utf8-jsp/ueditor.all.js"></script>
<script src="${ctxStatic}/plugins/h+/js/content.min.js?v=1.0.0"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/validate/jquery.validate.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/validate/messages_zh.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/demo/form-validate-demo.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/layer2.4/layer.js"></script>

<script src="${ctxStatic}/plugins/h+/js/bootstrap.min.js?v=3.3.5"></script>
<script src="${ctxStatic}/plugins/h+/js/content.min.js?v=1.0.0"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/chosen/chosen.jquery.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/jsKnob/jquery.knob.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/jasny/jasny-bootstrap.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/datapicker/bootstrap-datepicker.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/prettyfile/bootstrap-prettyfile.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/nouslider/jquery.nouislider.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/switchery/switchery.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/ionRangeSlider/ion.rangeSlider.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/iCheck/icheck.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/clockpicker/clockpicker.js"></script>
<script src="${ctxStatic}/plugins/h+/js/plugins/cropper/cropper.min.js"></script>
<script src="${ctxStatic}/plugins/h+/js/demo/form-advanced-demo.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/ajaxfileupload.js"></script>

<script src="${pageContext.request.contextPath}/resources/plugins/ueditor1_4_2-utf8-jsp/ueditor.config.js"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/ueditor1_4_2-utf8-jsp/ueditor.all.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/plugins/ueditor1_4_2-utf8-jsp/lang/zh-cn/zh-cn.js"></script>


<script type="text/javascript">

</script>

<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
<script type="text/javascript">
    <!-- 实例化编辑器 -->
    var ue = UE.getEditor('container');
    <!-- 自定义上传图片-->
    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function(action) {
        if (action == 'uploadimage' || action == 'uploadfile') {
            return '${ctx}/ue/uploadImageForUE.ac';
        } else {
            return this._bkGetActionUrl.call(this, action);
        }
    };

    //对编辑器的操作最好在编辑器ready之后再做
    ue.ready(function() {
        //设置编辑器的内容
        ue.setContent('');
        //获取html内容，返回: <p>hello</p>
        var html = ue.getContent();
        //获取纯文本内容，返回: hello
        var txt = ue.getContentTxt();
        ue.setContent('${row.graphicDetails}');

    });



    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    var picPath='<%=ConfigUtil.get("OSSURL")%>';
    var id='${id}';
    if(id!=null&&id!=''){
        $("#imgUpdate").attr("src", picPath + '${row.picture}');
    }else{
      //doSubmit();
    }

    //关闭iframe
    $('#btn_close').click(function(){
        parent.layer.close(index);
    });
    //关闭iframe
    $('#btn_close1').click(function(){
        parent.layer.close(index);
    });
    function  doSubmit()//提交保存
    {
        var id=$("id").val();//id
        var title=$("#title").val();//名称
        var picture=$("#picture").val();//logo
        if(picture==null||picture==undefined||picture==''){
            picture = '${row.picture}';
            $("#picture").val(picture);
        }
        var container=ue.getContent();//编辑框内容
        $("#graphicDetails").val(container);
        var description=$("#description").val();//地址
        var isOk=true;
        if(title==null||title==undefined||title==''){alert("请输入标题");isOk= false;}
        if(picture==null||picture==undefined||picture==''){alert("请上传图片");isOk= false;}
        if(isOk){
            if(id==null||id==undefined||id==''){
                saveOrUpdate();
            }else{
                $.ajax( {
                    url:'${pageContext.request.contextPath}/dynamic/?updateDynamic',
                    type:'post',
                    cache:false,
                    dataType:'json',
                    success:function(data) {
                        alert("操作成功")
                    },
                    error : function() {
                        alert("操作失败！");
                    }
                });
            }
        }else
        {
            return false;
        }
    }

    function saveOrUpdate() {

        var container=ue.getContent();//编辑框内容
        $("#graphicDetails").val(container);

        $.ajax( {
            url:'${pageContext.request.contextPath}/dynamic/doSave.ac',// 跳转到 action
            data:$("#form_brand").serialize(),
            type:'post',
            cache:false,
            dataType:'json',
            success:function(data) {
                if(data=="success")
                {
                    alert("操作成功！");

                    parent.layer.close(index);
                    parent.queryParams();
                }else
                {
                    alert("操作失败！");
                }
            },
            error : function() {
                alert("操作失败！");
            }
        });
    }


    // var picPath='http://9900oss.oss-cn-hangzhou.aliyuncs.com/';

    function uploadFile(obj,id,picId){//上传图片
        var labid = "";
        //var detailId = $("#detailId").val();
        //$("#"+id).css("background","url(${pageContext.request.contextPath}/resources/assets/images/waiting.gif) no-repeat 0 0/100% 100%");
        $.ajaxFileUpload({
            url: '${pageContext.request.contextPath}/common/doUploadFile.ac',
            secureuri: false,
            type:'post',
            fileElementId: obj,
            dataType: 'text',
            success: function(data, status) {
                var img=JSON.parse(data);
                $("#"+id).attr("src",picPath+img.path);
                $("#picture").val(img.path);

            },
            error: function(data, status, e) {
                alert(e);
            }
        });
    }


    function checkNumber(obj) {
        var reg=/^[0-9]{1,}(?:.[0-9]{0,2})?$/;

        if(!reg.test(obj.value))
        {
            alert("请正确输入数字,且保留小数点后2位");
            obj.value="0.0";
        }
    }

    function showOrhideOpetion(){
        if($("#pbrand_is_periodization").is(':checked')){
            $("#period").show();
            $("#periodization_hide").val(1);
        }else{
            $("#period").hide();
            $("#periodization_hide").val(0);
        }
    }


    $(function(){
        $("#form_brand").validate();
        initPeriod();
    });

    //初始化分配table行号
    function initPeriod(){
        $("#period_table tbody").find("tr").each(function(){
            var row_num =$(this).prevAll().length + 1;//行号
            $(this).children("td:first").html(row_num);
        });
    }


    function addRow(){
        var row_num = $("#period_table tbody tr:last").prevAll().length+2;
        var tr ='<tr>'
                +'<td>'+row_num+'</td>'
                +'<td><input type="number" name="scale" onkeyup= "if( !/^[1-9][0-9]$|^[0-9]$|^0$/.test(this.value)){alert(\'请输入0-100的整数\');this.value=\'\';}" ></td>'
                +'<td>'
                +'<a id="deleteRow" class="edit ml10" href="javascript:void(0);" onClick="deleteRow(this);" title="删除本行">'
                +'<i class="glyphicon glyphicon-minus"></i>'
                +'</a></td></tr>';
        $("#period_table tbody tr:last").after(tr);
    }

    function deleteRow(obj){
        $(obj).parent().parent().remove();
        initPeriod();
    }
</script>

</html>

